<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>LMovieClip</title>
    <script type="text/javascript" src="lufylegend-1.9.3.min.js"></script>
    <script type="text/javascript" src="lufylegend.ui-0.10.0.min.js"></script>
    <script type="text/javascript" src="../src/LMovieClip.js"></script>
</head>

<body style="margin:0px 0px 0px 0px;">
    <div id="content"></div>
    <script type="text/javascript">
        init(20,"content",600,500,main);
        // 要加载的数据
        var loadData = new Array(
            {name:"player",path:"./images/player.png"},
            {name:"1",path:"./images/1.png"},
            {name:"2",path:"./images/2.png"},
            {name:"3",path:"./images/3.png"},
            {name:"4",path:"./images/4.png"},
            {name:"5",path:"./images/5.png"},
            {name:"6",path:"./images/6.png"},
            {name:"7",path:"./images/7.png"},
            {name:"8",path:"./images/8.png"},
            {name:"9",path:"./images/9.png"},
            {name:"10",path:"./images/10.png"}
        );
        // 加载的图像列表
        var dataList={};

        function main(){
            LGlobal.setDebug(true);
            // 加载
            LLoadManage.load(
                loadData,
                function(progress){
                },
                function(result){
                    dataList = result;
                    gameInit();
                }
            );
        }
        var mc1, mc2, gotoAndPlayText, gotoAndStopText, speedText, infoLabel, runningState;
        function gameInit(){
            var layer=new LSprite();
            addChild(layer);

            // mc
            mc1=new LMoveClip(dataList["player"], 120, 210, 4);
            mc1.x=10;
            mc1.y=10;
            mc1.setSpeed(5);
            layer.addChild(mc1);
            mc1.addEventListener(LEvent.ENTER_FRAME, onFrame);
            var images=[];
            for (var i = 0; i < 10; i++) {
                images.push(dataList[(i+1)+""]);
            };
            mc2=new LMoveClip(images);
            mc2.x=400;
            mc2.y=50;
            mc2.setSpeed(10);
            mc2.setLable("f10", 10);
            mc2.addFrameScript("f10", framScript,"testparam");
            layer.addChild(mc2);
            // mc2.gotoAndStop("f0");

            var label=new LTextField();
            label.x=450;
            label.y=150;
            label.text="mc2";
            layer.addChild(label);

            // 播放控制
            var playButton=new LButtonSample1("play");
            playButton.x=mc1.x;
            playButton.y=250;
            playButton.addEventListener(LMouseEvent.MOUSE_UP, onClickPlay);
            layer.addChild(playButton);

            var stopButton=new LButtonSample1("stop");
            stopButton.x=75;
            stopButton.y=playButton.y;
            stopButton.addEventListener(LMouseEvent.MOUSE_UP, onClickStop);
            layer.addChild(stopButton);

            var prevFrameButton=new LButtonSample1("prevFrame");
            prevFrameButton.x=140;
            prevFrameButton.y=playButton.y;
            prevFrameButton.addEventListener(LMouseEvent.MOUSE_UP, onClickPrevFrame);
            layer.addChild(prevFrameButton);

            var nextFrameButton=new LButtonSample1("nextFrame");
            nextFrameButton.x=268;
            nextFrameButton.y=playButton.y;
            nextFrameButton.addEventListener(LMouseEvent.MOUSE_UP, onClickNextFrame);
            layer.addChild(nextFrameButton);

            // gotoAndPlay
            gotoAndPlayText=new LTextField();
            gotoAndPlayText.setType(LTextFieldType.INPUT);
            gotoAndPlayText.width=30;
            gotoAndPlayText.text="1";
            gotoAndPlayText.x=playButton.x;
            gotoAndPlayText.y=310;
            layer.addChild(gotoAndPlayText);
            var gotoAndPlayButton=new LButtonSample1("gotoAndPlay");
            gotoAndPlayButton.x=170;
            gotoAndPlayButton.y=gotoAndPlayText.y-10;
            gotoAndPlayButton.addEventListener(LMouseEvent.MOUSE_UP, onClickGotoAndPlay);
            layer.addChild(gotoAndPlayButton);

            // gotoAndStop
            gotoAndStopText=new LTextField();
            gotoAndStopText.setType(LTextFieldType.INPUT);
            gotoAndStopText.width=30;
            gotoAndStopText.text="1";
            gotoAndStopText.x=playButton.x;
            gotoAndStopText.y=360;
            layer.addChild(gotoAndStopText);
            var gotoAndStopButton=new LButtonSample1("gotoAndStop");
            gotoAndStopButton.x=170;
            gotoAndStopButton.y=gotoAndStopText.y-10;
            gotoAndStopButton.addEventListener(LMouseEvent.MOUSE_UP, onClickGotoAndStop);
            layer.addChild(gotoAndStopButton);

            // speed
            speedText=new LTextField();
            speedText.setType(LTextFieldType.INPUT);
            speedText.width=30;
            speedText.text="5";
            speedText.x=playButton.x;
            speedText.y=410;
            layer.addChild(speedText);
            var speedButton=new LButtonSample1("speed");
            speedButton.x=170;
            speedButton.y=speedText.y-10;
            speedButton.addEventListener(LMouseEvent.MOUSE_UP, onClickSpeed);
            layer.addChild(speedButton);

            // 信息显示
            infoLabel=new LTextField();
            infoLabel.x=playButton.x;
            infoLabel.y=450;
            layer.addChild(infoLabel);
        }
        function framScript (mc,param) {
            mc.stop();
            trace("mc2.addFrameScript params: '"+param+"'");
            trace("mc2.currentFrame: "+mc.getCurrentFrame());
            trace("mc2.currentFrameLabel: '"+mc.getCurrentFrameLabel()+"'");
        }
        function updateInfo () {
            if (mc1.isPlaying()) {
                infoLabel.text="currentFrame: "+mc1.getCurrentFrame();
            }
            else
            {
                infoLabel.text="currentFrame: "+mc1.getCurrentFrame()+"   stoped";
            }
        }
        function onFrame (event) {
            updateInfo();
        }
        function onClickPlay (event) {
            mc1.play();
        }
        function onClickPrevFrame (event) {
            mc1.prevFrame();
        }
        function onClickNextFrame (event) {
            mc1.nextFrame();
        }
        function onClickStop (event) {
            mc1.stop();
        }
        function onClickGotoAndPlay (event) {
            var frame=parseInt(gotoAndPlayText.text);
            if (isNaN(frame)) {
                frame=1;
            };
            mc1.gotoAndPlay(frame);
        }
        function onClickGotoAndStop (event) {
            var frame=parseInt(gotoAndStopText.text);
            if (isNaN(frame)) {
                frame=1;
            };
            mc1.gotoAndStop(frame);
        }
        function onClickSpeed (event) {
            var speed=parseInt(speedText.text);
            if (isNaN(speed)) {
                speed=1;
            };
            mc1.setSpeed(speed);
        }
    </script>
</body>

</html>
